from django.contrib import admin

# Register your models here.
from django.db.models import F

from .models import Students, Place, Restaurant, Waiter, Teacher, SchoolClass

# admin.site.register(Students)
admin.site.register(Place)
# admin.site.register(Restaurant)
admin.site.register(Waiter)
# admin.site.register(Teacher)
admin.site.register(SchoolClass)

class StudentAdmin(admin.ModelAdmin):
    list_display = ['name', 'age','sex']
    ordering = ['age']
    # 这里必须是函数名的字符串
    actions = ['age_add_one']
    list_display_links = ('name', 'age', 'sex',)
    # 类方法也同样是3个参数！
    def age_add_one(modeladmin, request, queryset):
        queryset.update(age=F('age') + 1)

    age_add_one.short_description = "年龄增加一岁"

admin.site.register(Students,StudentAdmin)


class RestaurantAdmin(admin.ModelAdmin):
    list_display = ['place','name','serves_hot_dogs','serves_pizza','start_time']
    list_display_links = ("place", "name",)
    # list_editable = ("name",)
    # exclude = ('place','name','serves_hot_dogs',)
    # fields = ('serves_pizza',)
    # readonly_fields = ("name",)
    list_filter = ('place','name',)
    search_fields = ('name',)
    empty_value_display = '-empty-'
admin.site.register(Restaurant, RestaurantAdmin)

# class RestaurantAdmin(admin.ModelAdmin):
#     list_display = ['place','name','serves_hot_dogs','serves_pizza']

@admin.register(Teacher)
class TeacherAdmin(admin.ModelAdmin):
    ordering = ('name',)
    filter_horizontal = ('school_class',)